﻿using Digitalmes.Domain.Entities.Mes.Masters;

namespace Digitalmes.Application.Mes.Masters.Lines.Commands;

/// <summary>
/// 更新产线信息命令。
/// </summary>
/// <param name="Line"></param>
public record UpdateLineCommand(MdLineDto Line) : IRequest<IResult<bool>>;

internal sealed class UpdateLineCommandHandler(IRepository<MdLine> repo) : IRequestHandler<UpdateLineCommand, IResult<bool>>
{
    public async Task<IResult<bool>> Handle(UpdateLineCommand request, CancellationToken cancellationToken)
    {
        var line = request.Line.Adapt<MdLine>();
        var ok = await repo.UpdateAsync(line, m => new
        {
            m.LineName,
            m.Remark,
            m.Status,
            m.UpdatedBy,
            m.UpdatedTime,
        }, cancellationToken);
        return Result.From(ok);
    }
}
